(function() {
  'use strict';
  angular.module('controllers.dataManager.dataQualityMonitor')
    .controller('alarmStatisticsforBPCtrl', alarmStatisticsforBPCtrl);

  function alarmStatisticsforBPCtrl($scope, $http, alarmStatisticsforBPService, $filter, CoreLoading, dataQualityMonitorService) {
    $scope.flag = {
      state: true,
      arrow: false,
      show: 'view'
    };
    var time = new Date();
    var date = new Date(time.getFullYear(), time.getMonth(), time.getDate() - 1);
    $scope.params = {
      date: date,
      module: '1'
    };

    var myEcharts = echarts.init(document.getElementById('doc'));
    $scope.search = function() {
      if (!$scope.flag.state) {
        $scope.flag.state = true;
        return;
      }
      var data = alarmStatisticsforBPService.getName($scope.params);
      var legendName = data.legendName;
      var moduleName = data.moduleName;
      var xAxisData = [];
      var seriesData = [];

      CoreLoading.setState(true);
      var send = alarmStatisticsforBPService.fmtSendData($scope.params);
      var timeTitle = alarmStatisticsforBPService.fmtDateTitle(send);
      $scope.title = timeTitle + '数据' + moduleName + '统计';
      alarmStatisticsforBPService.alarmQuery(send, function(res) {
        if (res.state === '10000' && res.data.length >= 1) {
          myEcharts.clear();
          $scope.flag.state = false;
          $scope.flag.arrow = false;
          $scope.flag.show = 'view';
          angular.forEach(res.data, function(item) {
            xAxisData.push(item.timePoint);
            seriesData.push(item.volume);
          });
          var option = alarmStatisticsforBPService.initChart(xAxisData, seriesData, $scope.title, legendName);
          option.tooltip.formatter = alarmStatisticsforBPService.getFormatterFn('笔');
          myEcharts.setOption(option);
        } else {
          dataQualityMonitorService.queryError($scope.flag, '查询无数据');
        }
        CoreLoading.setState(false);
      });
    };
    $scope.search();
  }

  alarmStatisticsforBPCtrl.$inject = ['$scope', '$http', 'alarmStatisticsforBPService', '$filter', 'CoreLoading', 'dataQualityMonitorService'];

})();